package com.grandbroad.eim.adapter;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.PagerAdapter;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.easy.west.westclient.api.search.bean.SearchBean;
import com.grandbroad.eim.R;

import java.util.ArrayList;
import java.util.List;

public class SearchResultPageAdapter extends PagerAdapter {
    private AppCompatActivity activity;
    private List<String> titles = new ArrayList<>();
    private List<SearchBean.LiveroomDTOListBean> listBeanList = new ArrayList<>();
    private List<SearchBean.VodDTOSBean> vodDTOSBeanslist = new ArrayList<>();
    private String name;
    public void setListBeanList(List<SearchBean.LiveroomDTOListBean> listBeanList) {
        this.listBeanList = listBeanList;
    }

    public void setVodDTOSBeanslist(List<SearchBean.VodDTOSBean> vodDTOSBeanslist) {
        this.vodDTOSBeanslist = vodDTOSBeanslist;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setTitles(List<String> titles) {
        this.titles = titles;
    }


    public SearchResultPageAdapter(AppCompatActivity activity) {
        this.activity =activity;
        titles.add("视频");
        titles.add("LIVE");
    }

    @Override
    public int getCount() {
        return 2;
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
        return view ==(View) o;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View view = LayoutInflater.from(container.getContext()).inflate(R.layout.recycler_view,container,false);
        RecyclerView recyclerView = view.findViewById(R.id.recycler_vod);
        if (position==0)
        {
            //视频
            SearchResultAdapter resultAdapter = new SearchResultAdapter(activity);
            resultAdapter.setType("视频");
            resultAdapter.setSearch_name(name);
            resultAdapter.setSearchVodList(vodDTOSBeanslist);
            resultAdapter.notifyDataSetChanged();
            recyclerView.setLayoutManager(new LinearLayoutManager(container.getContext()));
            recyclerView.setAdapter(resultAdapter);


        }
        else
        {
            //LIVE
            SearchResultAdapter resultAdapter = new SearchResultAdapter(activity);
            resultAdapter.setType("LIVE");
            resultAdapter.setSearchLiveList(listBeanList);
            resultAdapter.setSearch_name(name);
            resultAdapter.notifyDataSetChanged();
            recyclerView.setLayoutManager(new LinearLayoutManager(container.getContext()));
            recyclerView.setAdapter(resultAdapter);

        }
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return titles.get(position);
    }
}
